00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00035 function mergePhotoRights(&$to, &$from) {
00036 if ($from->view == 1) $to->view = 1;
00037 if ($from->upload == 1) $to->upload = 1;
00038 if ($from->edit == 1) $to->edit = 1;
00039 if ($from->remove == 1) $to->remove = 1;
00040 if ($from->admin == 1) $to->admin = 1;
00041 }
00048 function testPhotoRight(&$rights, $rightname) {
00049 if ($_SESSION['usergroup'] == ADMIN) return true;
00050 if ($_SESSION['usergroup'] == DOZENT && $_SESSION['course'] != 0) return true;
00051 if ($rights) {
00052 if ($rights->admin) return true;
00053 $result = 0;
00054 eval('$result=$rights->'.$rightname.';');
00055 return $result == 1;
00056 } else return false;
00057 }
00069 function getGalleryRights() {
00070 global $settings, $db, $EZSQL_ERROR;
00071 $safecourse = Data::toMysql($_SESSION['course']);
00072 $safeuser = Data::toMysql($_SESSION['userid']);
00073 if ($_SESSION['usergroup'] == SCHUELER || $_SESSION['usergroup'] == GAST)
00074 $globalrights = $db->get_row("SELECT 1 as view, 0 as upload, 0 as edit, 0 as remove, 0 as admin FROM photogallery_rights WHERE course_id=".$safecourse." AND album_id='0' AND usr_id='0' LIMIT 1");
00075 else
00076 $globalrights = $db->get_row("SELECT * FROM photogallery_rights WHERE course_id=".$safecourse." AND album_id='0' AND usr_id='0' LIMIT 1");
00077 $userrights = $db->get_row("SELECT * FROM photogallery_rights WHERE course_id=".$safecourse." AND album_id='0' AND usr_id='".$safeuser."' LIMIT 1");
00078 if (!$db->num_rows) {
00079
00080
00081
00082
00083
00084 $globalrights = $db->get_row("SELECT 1 as view, 1 as upload, 1 as edit, 1 as remove, 0 as admin");
00085 }
00086 if ($globalrights) {
00087 if ($userrights) mergePhotoRights($globalrights, $userrights);
00088 return $globalrights;
00089 } else if ($userrights) return $userrights;
00090 }
00102 function getAlbumRights($albumID) {
00103 global $settings, $db, $EZSQL_ERROR;
00104 $safecourse = Data::toMysql($_SESSION['course']);
00105 $safeuser = Data::toMysql($_SESSION['userid']);
00106 $safealbum = Data::toMysql($albumID);
00107 $globalrights = $db->get_row("SELECT * FROM photogallery_rights WHERE course_id=".$safecourse." AND album_id='$safealbum' AND usr_id='0' LIMIT 1");
00108 $userrights = $db->get_row("SELECT * FROM photogallery_rights WHERE course_id=".$safecourse." AND album_id='$safealbum' AND usr_id='".$safeuser."' LIMIT 1");
00109 if ($globalrights) {
00110 if ($userrights) mergePhotoRights($globalrights, $userrights);
00111 return $globalrights;
00112 } else if ($userrights) return $userrights;
00113 }
00114 function echoRightsSelectors($prefix, $photo_view, $photo_upload, $photo_edit, $photo_delete, $photo_admin) {
00115 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_view' ";
00116 echo $photo_view == true ? 'checked=\'checked\'' : '';
00117 echo "/></td>";
00118 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_upload' ";
00119 echo $photo_upload == true ? 'checked=\'checked\'' : '';
00120 echo "/></td>";
00121 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_edit' ";
00122 echo $photo_edit == true ? 'checked=\'checked\'' : '';
00123 echo "/></td>";
00124 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_delete' ";
00125 echo $photo_delete == true ? 'checked=\'checked\'' : '';
00126 echo "/></td>";
00127 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_admin' ";
00128 echo $photo_admin == true ? 'checked=\'checked\'' : '';
00129 echo "/></td>";
00130 }
00131 function echoGalleryRightsSelectors($prefix, $photo_upload, $photo_edit, $photo_remove) {
00132 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_upload' ";
00133 echo $photo_upload == true ? 'checked=\'checked\'' : '';
00134 echo "/></td>";
00135 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_edit' ";
00136 echo $photo_edit == true ? 'checked=\'checked\'' : '';
00137 echo "/></td>";
00138 echo "<td class='tableCell' style='text-align:center;'><input type='checkbox' name='{$prefix}_remove' ";
00139 echo $photo_remove == true ? 'checked=\'checked\'' : '';
00140 echo "/></td>";
00141 }
00148 function echoRightsUserlist($condition) {
00149 global $db;
00150 $course = "";
00151 if ($_SESSION['course'] != 0) {
00152 $course = "AND user.ID IN( SELECT userID FROM user_course WHERE courseID='{$_SESSION['course']}')";
00153 }
00154 $query = "SELECT ID, Vorname, Nachname, Invisible, Usergroup FROM user WHERE user.ID > 0 $course AND user.Invisible=0 $condition";
00155 $query.= " ORDER BY user.Nachname, user.Vorname";
00156 $users = $db->get_results($query);
00157 if (count($users) > 0) {
00158 $i = 0;
00159 foreach($users as $user) {
00160 echo "<option ";
00161 if ($user->Invisible == 1) echo "style='font-style:italic'";
00162 echo " value='".$user->ID."' ";
00163 echo ">";
00164 echo Data::toHTML("$user->Nachname, $user->Vorname", false);
00165 echo "</option>\n";
00166 $i++;
00167 }
00168 return true;
00169 } else return false;
00170 }
00175 function getGalleryRight($rightname) {
00176 $rights = getGalleryRights();
00177 return testPhotoRight($rights, $rightname);
00178 }
00183 function getAlbumRight($rightname, $albumid) {
00184 $rights = getAlbumRights($albumid);
00185 return testPhotoRight($rights, $rightname);
00186 }